<?php
//----------------------------------
// 圈子模块
// Reload 2018-1-2
//----------------------------------
namespace Home\Controller;
use Think\Controller;
class CircleController extends Controller {
    /***
    **圈子详情页平台基础信息
    ***/
    public function get_info_circle(){
        //$info_s = S('info');
        //if($info_s) {
        //    return $info_s;
        //} else {
			$platform_id = I('get.id');
			$map['platform_id'] = $platform_id;
			$info = D('Circle')->get_one($map);
			$map = array();
			$map['id'] = $platform_id;
			$plat_name = D('Platform')->get_one($map,$field='name');
			$info['plat_name'] = $plat_name;
			if($info) {
            //    S('info',$info,86400);
				$res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>$info);
			} else {
				$res = array('errorCode'=>0,'msg'=>"暂无数据");
			}
			$this->ajaxReturn($res);
		//}
    }

    //获取平台评级
    public function get_circle_leve(){
        $platform_id = I('get.id');
        $map['platform_id'] = $platform_id;
        $list = M('PlatformGrade')->where($map)->field('count(*) as count,user_role,colligate')->group('user_role,colligate')->order('count(*) desc,colligate asc')->select();
        $list_all = M('PlatformGrade')->where($map)->field('count(*) as count,user_role,colligate')->group('colligate')->order('count(*) desc,colligate asc')->select();
        $count_user = 0;
        $count = 0;
        $count_push = 0;
       // return $list_all;
        foreach ($list_all as $k => $v) {
            $count = $count+$v['count'];
            $all_grade['all_count']=$count;
            $all_grade[]=$v;

        }
        foreach($list as $k=>$v){
            $role = $v['user_role'];

            if($role==1){
                $count_user = $count_user+$v['count'];
                $usre_grade['all_count']=$count_user;
                $usre_grade[]=$v;
            }else{
                $count_push = $count_push+$v['count'];
                $usre_push['all_count']=$count_push;
                $usre_push[]=$v;
            }
        }
        foreach ($usre_grade as $k => $v) {
           $count_percent = sprintf("%.0f",$v['count']/$usre_grade['all_count']*100);
           $usre_grade[$k]['count_percent']=$count_percent;
           $usre_grade[$k]['usre_grade']=$usre_grade['all_count'];
        }
        //unset($usre_grade['all_count']);
        //return ($usre_grade);
        foreach ($usre_push as $k => $v) {
           $count_percent = sprintf("%.0f",$v['count']/$usre_push['all_count']*100);
           $usre_push[$k]['count_percent']=$count_percent;
           $usre_push[$k]['usre_grade']=$usre_push['all_count'];
        }
        //unset($usre_push['all_count']);

        foreach ($all_grade as $k => $v) {
           $count_percent = sprintf("%.0f",$v['count']/$all_grade['all_count']*100);
           $all_grade[$k]['count_percent']=$count_percent;
           $all_grade[$k]['usre_grade']=$all_grade['all_count'];
        }
       // unset($usre_push['all_count']);
        if($usre_grade or $usre_push or $all_grade) {
            if(!$usre_grade) {
                $usre_grade = array('0'=>array('count'=>'','user_role'=>'','colligate'=>'','count_percent'=>'','usre_grade'=>''));
            }
            $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>array('usre_grade'=>$usre_grade[0],'usre_push'=>$usre_push[0],'all_grade'=>$all_grade[0]));
        } else {
            $res = array('errorCode'=>0,'msg'=>"暂无数据");
        }
        $this->ajaxReturn($res);
    }

    /**
     * [get_cricel_course 获取平台合规进程]
     * @param  [type] $platform_id [平台ID]
     * @return [type]              [description]
     */
    public function get_circle_course(){

        $platform_id=I('get.id');
        $map['platform_id'] = $platform_id;
        $info = M('Course')->where($map)->find();
        $count =  count($info)-2;
        $is_good = 0;
        $i = 0;
        foreach ($info as $k => $v) {
            if($k!='id' && $k!='platform_id' && $v==1){
                $is_good = $is_good+1;
            }
             if($k!='id' && $k!='platform_id'){
                switch ($k) {
                    case 'records':
                       $name = "金融局成功备案";
                       $order = 0;
                        break;
                    case 'deposit':
                       $name = "银行存管";
                       $order = 1;
                        break;
                    case 'object':
                       $name = "标的限额";
                       $order = 2;
                        break;
                    case 'risk':
                       $name = "风险提示";
                       $order = 3;
                        break;
                    case 'debt':
                       $name = "禁止债转";
                       $order = 4;
                        break;
                    case 'melt':
                       $name = "禁止自融";
                       $order = 5;
                        break;
                    case 'crowd':
                       $name = "禁止众筹";
                       $order = 6;
                        break;
                    case 'false_sign':
                       $name = "禁止假标";
                       $order = 7;
                        break;
                    case 'capital':
                       $name = "无资金池";
                       $order = 8;
                        break;
                    case 'sign':
                       $name = "禁止拆标";
                       $order = 9;
                        break;
                    case 'borrow':
                       $name = "电子签章";
                        $order = 10;
                        break;
                    case 'pack_asset':
                       $name = "禁止打包资产";
                       $order = 11;
                        break;
                    case 'lending':
                       $name = "禁止放贷";
                       $order = 12;
                        break;
                    case 'offline':
                       $name = "禁止线下推广";
                       $order = 13;
                        break;
                    case 'announce':
                       $name = "信息披露完整";
                       $order = 14;
                        break;
                    case 'obj_info':
                       $name = "标的信息披露";
                       $order = 15;
                        break;
                    case 'assure':
                       $name = "禁止自担保";
                       $order = 16;
                        break;
                    case 'safety':
                       $name = "信息系统安全评估";
                       $order = 17;
                        break;
                    // case 'sell':
                    //    $name = "禁止代销";
                    //     break;
                    case 'brenk':
                       $name = "无承诺保本保息";
                       $order = 18;
                        break;

                    case 'product':
                       $name = "不代销理财产品";
                       $order = 19;
                        break;

                    case 'business':
                       $name = "网贷中介营业执照";
                       $order = 20;
                        break;

                    case 'telecom':
                       $name = "互金专属ICP经营许可证";
                       $order = 21;
                        break;
                    default:
                        # code...
                        break;
                }
                if($v==0){
                    $val = 1;
                }elseif ($v==1) {
                    $val = 2;
                }elseif ($v==2) {
                    $val = 3;
                }
                $arr[$i]['name'] = $name;
                $arr[$i]['val'] = $val;
                $arr[$i]['order'] = $order;
                $i = $i+1;
            }

        }
        $sort = array(
        'direction' => 'SORT_ASC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序
        'field'     => 'order',       //排序字段
        );

         $arrSort = array();
        foreach($arr AS $uniqid => $row){
            foreach($row AS $key=>$value){
                $arrSort[$key][$uniqid] = $value;
            }
        }
        if($sort['direction']){
            array_multisort($arrSort[$sort['field']],constant($sort['direction']),$arr);
        }

            $is_good = sprintf("%.0f",$is_good/$count*100);
        //    $cricel_course = array('info'=>$arr,'is_good'=>$is_good);
            if($arr or $is_good) {
                $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>array('info'=>$arr,'is_good'=>$is_good));
            } else {
                $res = array('errorCode'=>0,'msg'=>"暂无数据");
            }
            $this->ajaxReturn($res);
    }

    /**
     * [get_order 抓取平台在网贷之家和网贷天眼的排名数据]
     * @param  [type] $wdzj_url   [网贷之家的平台详情页地址]
     * @param  [type] $wdeye_url [网贷天眼的平台详情页地址]
     * @return [type]            [array]
     */
/*    public function get_order(){
         //采集
        $arr_data = S('arr_data');
        $platform_id = I('get.id');
        //获取圈子基础信息
        $circle_info = $this->get_program_circle($platform_id);
        if($arr_data){
            return $arr_data;
        }else{
        //排名数据
            $wdeye_url = $circle_info['eye_url'];
            $wdzj_url = $circle_info['home_url'];
            import("Api.SnoopyApi");
            $Snoopy = new \SnoopyApi();
            //网贷之家排名抓取
            $Snoopy->fetch($wdzj_url);//要抓取的网站
            $a = $Snoopy->results;
            $str = mb_convert_encoding($a, 'UTF-8', 'UTF-8');//中文编码
            $wdzj_order =  '/<b>（(.+?)名）<\/b>/is'; //抓取规则 (上线时间)
            preg_match($wdzj_order , $str , $wdzj_order);
            $wdzj_order = $wdzj_order[1]?$wdzj_order[1]:'-';
            //网贷天眼排名
            $Snoopy->fetch($wdeye_url);//要抓取的网站
            $a = $Snoopy->results;
            $str = mb_convert_encoding($a, 'UTF-8', 'UTF-8');//中文编码
            $wdty_order =  '/<span>排名:<\/span><strong>(.+?)<\/strong>/is'; //抓取规则 (上线时间)
            preg_match($wdty_order , $str , $wdty_order);
            $wdty_order = $wdty_order[1]?$wdty_order[1]:'-';
        //    $arr = array('wdzj_order'=>$wdzj_order,'wdty_order'=>$wdty_order);
           // print_r($arr);
            if($wdzj_order or $wdty_order) {
                $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>array('wdzj_order'=>$wdzj_order,'wdty_order'=>$wdty_order));
            } else {
                $res = array('errorCode'=>0,'msg'=>"暂无数据");
            }
            $this->ajaxReturn($res);
            S("arr_data",$res,array('type'=>'file','expire'=>86400));


        }

    }*/
    public function get_order(){
        // public function get_order(){
         //采集
        $platform_id = I('get.id');
        $arr_data = S('arr_data'.$platform_id);
        //获取圈子基础信息
        $circle_info = $this->get_program_circle($platform_id);
        if($arr_data){
            return $arr_data;
        }else{
        //排名数据
            $wdeye_url = $circle_info['eye_url'];
            $wdzj_url = $circle_info['home_url'];
            import("Api.SnoopyApi");
            $Snoopy = new \SnoopyApi();
            //网贷之家排名抓取
            $a = $this->get_file($wdzj_url);
            $str = mb_convert_encoding($a, 'UTF-8', 'UTF-8');//中文编码
            $wdzj_order =  '/<span class=\"col\"><b>(.+?)<\/b>名/is'; //抓取规则 (上线时间)  
            preg_match($wdzj_order , $str , $wdzj_order);
            $wdzj_order = $wdzj_order[1]?$wdzj_order[1]:'-';
            //网贷天眼排名
            $Snoopy->fetch($wdeye_url);//要抓取的网站
            $a = $Snoopy->results; 
            $str = mb_convert_encoding($a, 'UTF-8', 'UTF-8');//中文编码
            $wdty_order =  '/<span>排名:<\/span><strong>(.+?)<\/strong>/is'; //抓取规则 (上线时间)  
            preg_match($wdty_order , $str , $wdty_order);
            $wdty_order = $wdty_order[1]?$wdty_order[1]:'-';
            $arr = array('wdzj_order'=>$wdzj_order,'wdty_order'=>$wdty_order);
            S("arr_data".$platform_id,$arr,array('type'=>'file','expire'=>86400));
            if($wdzj_order or $wdty_order) {
                $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>array('wdzj_order'=>$wdzj_order,'wdty_order'=>$wdty_order));
            } else {
                $res = array('errorCode'=>0,'msg'=>"暂无数据");
            }
            $this->ajaxReturn($res);
        }
       
    }
    /**
    获取https网页内容
    **/
       function get_file($url){
            $curl = curl_init();
            curl_setopt($curl, CURLOPT_URL, $url);
            curl_setopt($curl, CURLOPT_HEADER, 1);
            curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
            curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
            $data = curl_exec($curl);
            curl_close($curl);
            return $data;
    }






    /**
     * [circle_list 平台圈子列表]
     * @return [type] [description]
     */
    public function circle_list(){
        //平台列表
        $map['status']=1;
		$map['id'] = array('neq',4);
        $list = D('Circle')->get_all($map,$field='*');
        $map = array();
        foreach ($list as $k => $v) {
            //加入圈子人数
            $map['platform_id'] = $v['platform_id'];
            $group = M('ImGroup')->where($map)->find();
            $map = array();
            $map['group_id'] = $group['groupid'];
            $map['status'] = 0;
            $group_count = M('ImGroupUser')->where($map)->count();
            $list[$k]['group_count'] = $group_count;
             //深度评测
            $map = array();
            $map['platform_id'] = $v['platform_id'];
            $depth_count = M('OtthAppraisal')->where($map)->count();//深度评测条数
            $depth_count1 = M('Depth')->where($map)->count();  //深度评测条数
            $list[$k]['depth_count'] = $depth_count;
            //热门点评
            $commen_count = M('PlatformCommentary')->where($map)->count();//短评条数
            $annou_count = M('CircleAnnounce')->where($map)->count();//信批评论条数
            $opin_count = M('CircleOpinion')->where($map)->count();//舆情条数
            $total_count = $depth_count1+$commen_count+$annou_count+$opin_count;//总的热评条数
            $list[$k]['total_count'] = $total_count;
            $list[$k]['cricel_leve']=$this->get_cricel_leve($v['platform_id']);
            $hot = $v['is_hot'];
            if($hot==1){
                $hot_list[] = $list[$k];
            }
			  //查询投顾
             $maps = array();
             $maps['push_platform_id'] = $v['platform_id'];
             $push_user= D('Recommend')->get_one($maps);
             //echo D('Recommend')->_sql();
             $maps = array();
             $maps['id'] = $push_user['user_id'];
             $push_user['user'] = D('User')->get_one($maps);
             $list[$k]['push_user'] =$push_user;
			 //print_r($push_user);die;
			/*
			$pushlist_temp_name = 'temp_'.$k;
			if(S($pushlist_temp_name)){
				$push_list = S($pushlist_temp_name);
			}else{
				$push_list = $this->push_list_recom($v['platform_id']);
				$push_list = $push_list['push_list'][0];
				S($pushlist_temp_name,$push_list,86400);
				//print_r(S('pushlist_temp'));
			}
             
             $list[$k]['push_user'] = $push_list;*/
			 
        }
		//print_r($list);die;
        if($list or $hot_list) {
            $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>array('list'=>$list,'hot_list'=>$hot_list));
        } else {
            $res = array('errorCode'=>0,'msg'=>"暂无数据");
        }
        $this->ajaxReturn($res);

    }

	    public function push_list_recom($platform_id){

       
        $user_id = $_SESSION['user']['id'];
        $map['id'] = $user_id;
        $user = D('User')->get_one($map);
        // return(1);d
        if($user){
            $map = array();
            $map['user_id'] = $user['referral'];
            $recom = D('Recommend')->get_one($map);
        }

         $map = array();
        $map['platform_id'] = $platform_id;
        $push_list = D('RecommendPlatform')->get_all($map,$field="*",$page=0,$pagenum=3);
        $push_count = D('RecommendPlatform')->count($map);
        foreach ($push_list as $k => $v) {
            $map=array();
            $recommend_id = $v['recommend_id'];
            $map['id'] = $recommend_id;
            $recommen= D('Recommend')->get_one($map);
             if($v['recommend_id']==$recom['id']){
                $push_list[$k]['is_fans'] = 1;
            }else{
                $push_list[$k]['is_fans'] = 0;
            }

            $map = array();
            $map['id'] = $recommen['user_id'];
            $push_list[$k]['user']= D('User')->get_one($map);
            //统计推手在该平台投资人
            $map = array();
            $map['referral'] = $recommen['user_id'];
            $push_list[$k]['info'] = $recommen;
            $referral= D('User')->get_all($map);
            $tz_count = 0;
            foreach ($referral as $key => $value) {
                //print_r($value);
                $map = array();
                $map['user_id'] = $value['id'];
                $map['platform_id'] = $platform_id;
                $r = D('UserObject')->get_one($map);
                if($r){
                    ;
                     $tz_count = $tz_count+1;
                }
            }
            $push_list[$k]['tz_count'] =$tz_count;
            //红包
            $push_list[$k]['packet'] = R('Packet/get_redpacket',array('user_id'=>$recommen['user_id'],'platform_id'=>$platform_id));
        }


        $sort = array(  
        'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序  
        'field'     => 'tz_count',       //排序字段  
        ); 

         $arrSort = array();  
        foreach($push_list AS $uniqid => $row){  
            foreach($row AS $key=>$value){  
                $arrSort[$key][$uniqid] = $value;  
            }  
        }  
        if($sort['direction']){  
            array_multisort($arrSort[$sort['field']],constant($sort['direction']),$push_list);  
        }  
        $push_list = array_slice($push_list,0,7);
        $push_list = array('push_list'=>$push_list,'push_count'=>$push_count,'user_info'=>$user['nickname']);
        return $push_list;
    }
	
	
	
	
	
    //投顾列表
    public function recom_list() {
         //投顾列表
        $user_id = I('post.userid');
        $map['id'] = $user_id;
        $user = D('User')->get_one($map);
        $map = array();
        if($user){
            $map['user_id'] = $user['referral'];
            $recom = D('Recommend')->get_one($map);
        }
        //$p = I('post.currentPage');
        //$pagenum = I('post.pageSize',10,int);
        //$pagenum = 10;
        //$p = ($p-1)*$pagenum;
        //$p = ($p-1)*$pagenum;

        $map = array();
			$push_list = D('RecommendPlatform')->where($map)->group('recommend_id')->select();
        //$push_list = D('RecommendPlatform')->where($map)->group('recommend_id')->limit($p='0',$pagenum='10')->select();

            foreach ($push_list as $k => $v) {
                $push_list[$k]['user_info'] = $user['nickname'];
                $recommend_id = $v['recommend_id'];
                $map['id'] = $recommend_id;
                $recommen= D('Recommend')->get_one($map);
                if($recommen['id']==$recom['id']){
                    $push_list[$k]['is_fans'] = 1;
                }else{
                    $push_list[$k]['is_fans'] = 0;
                }

                //统计徒弟数量

                $where = array();
                $where['referral'] = $recommen['user_id'];
                $push_list[$k]['fans_count']=D('User')->count($where);
                $platform_id_list = explode(',', $recommen['push_plat_id']);
               // print_r()
                foreach ($platform_id_list as $ke => $va) {
                     $map['id'] = $va;
                     $plat_info = D('Platform')->get_one($map);
                     $push_list[$k]['platform_id_list_arr'][] = $plat_info['name'];
                }
                $push_list[$k]['platform_id_list'] = implode(',', $push_list[$k]['platform_id_list_arr']);
                $map = array();
                $map['referral'] = $recommen['user_id'];
                $push_list[$k]['info'] = $recommen;
                $referral= D('User')->count($map);
                $push_list[$k]['referral'] = $referral;
                $map = array();
                $map['id'] = $recommen['user_id'];
                $userinfo =  D('User')->get_one($map);
                if($userinfo){
                    $push_list[$k]['user']=$userinfo;
                }else{
                    unset($push_list[$k]);
                }
                

            }
    //    print_r($push_list);die;

        $sort = array(  
        'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序  
        'field'     => 'referral',       //排序字段  
        ); 

         $arrSort = array();  
        foreach($push_list AS $uniqid => $row){  
            foreach($row AS $key=>$value){  
                $arrSort[$key][$uniqid] = $value;  
            }  
        }  
        if($sort['direction']){  
            array_multisort($arrSort[$sort['field']],constant($sort['direction']),$push_list);  
        }  

        foreach ($push_list as $k => $v) {

            $recommend_id = $v['recommend_id'];
            $arr[$recommend_id] = $push_list[$k];

        }
         $push_list = array_slice($push_list,0,86400);

        if($push_list) {
            $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>$push_list);
        } else {
            $res = array('errorCode'=>0,'msg'=>"暂无数据");
        }
        $this->ajaxReturn($res);
    }

	
	
	
	

    /**
     * [get_cricel_leve 获取平台评级数据]
     * @param  [type] $platform_id [平台ID]
     * @return [type]              [array]
     */
    public function get_cricel_leve($platform_id){
        $map['platform_id'] = $platform_id;
        $list = M('PlatformGrade')->where($map)->field('count(*) as count,user_role,colligate')->group('user_role,colligate')->order('count(*) desc,colligate asc')->select();
        $list_all = M('PlatformGrade')->where($map)->field('count(*) as count,user_role,colligate')->group('colligate')->order('count(*) desc,colligate asc')->select();
        $count_user = 0;
        $count = 0;
        $count_push = 0;
       // return $list_all;
        foreach ($list_all as $k => $v) {
            $count = $count+$v['count'];
            $all_grade['all_count']=$count;
            $all_grade[]=$v;

        }
        foreach($list as $k=>$v){
            $role = $v['user_role'];

            if($role==1){
                $count_user = $count_user+$v['count'];
                $usre_grade['all_count']=$count_user;
                $usre_grade[]=$v;
            }else{
                $count_push = $count_push+$v['count'];
                $usre_push['all_count']=$count_push;
                $usre_push[]=$v;
            }
        }
        foreach ($usre_grade as $k => $v) {
           $count_percent = sprintf("%.0f",$v['count']/$usre_grade['all_count']*100);
           $usre_grade[$k]['count_percent']=$count_percent;
           $usre_grade[$k]['usre_grade']=$usre_grade['all_count'];
        }
        //unset($usre_grade['all_count']);
        //return ($usre_grade);
        foreach ($usre_push as $k => $v) {
           $count_percent = sprintf("%.0f",$v['count']/$usre_push['all_count']*100);
           $usre_push[$k]['count_percent']=$count_percent;
           $usre_push[$k]['usre_grade']=$usre_push['all_count'];
        }
        //unset($usre_push['all_count']);

        foreach ($all_grade as $k => $v) {
           $count_percent = sprintf("%.0f",$v['count']/$all_grade['all_count']*100);
           $all_grade[$k]['count_percent']=$count_percent;
           $all_grade[$k]['usre_grade']=$all_grade['all_count'];
        }
       // unset($usre_push['all_count']);
        $data = array('usre_grade'=>$usre_grade[0],'usre_push'=>$usre_push[0],'all_grade'=>$all_grade[0]);
        return ($data); 
    }
    /**
     * [get_cricel_course 获取平台合规进程]
     * @param  [type] $platform_id [平台ID]
     * @return [type]              [description]
     */
    public function get_cricel_course($platform_id=1){

         $val_pass = I('get.val');
         if($val_pass){
            $platform_id=I('post.id');
         }
        $map['platform_id'] = $platform_id;
        $info = D('Course')->where($map)->find();
        $count =  count($info)-2;
        $is_good = 0;
        $i = 0;
        foreach ($info as $k => $v) {
            if($k!='id' && $k!='platform_id' && $v==1){
                $is_good = $is_good+1;
            }
             if($k!='id' && $k!='platform_id'){
                switch ($k) {
                    case 'records':
                       $name = "金融局成功备案";
                       $order = 0;
                        break;
                    case 'deposit':
                       $name = "银行存管";
                       $order = 1;
                        break;
                    case 'object':
                       $name = "标的限额";
                       $order = 2;
                        break;
                    case 'risk':
                       $name = "风险提示";
                       $order = 3;
                        break;
                    case 'debt':
                       $name = "禁止债转";
                       $order = 4;
                        break;
                    case 'melt':
                       $name = "禁止自融";
                       $order = 5;
                        break;
                    case 'crowd':
                       $name = "禁止众筹";
                       $order = 6;
                        break;
                    case 'false_sign':
                       $name = "禁止假标";
                       $order = 7;
                        break;
                    case 'capital':
                       $name = "无资金池";
                       $order = 8;
                        break;
                    case 'sign':
                       $name = "禁止拆标";
                       $order = 9;
                        break;
                    case 'borrow':
                       $name = "电子签章";
                        $order = 10;
                        break;
                    case 'pack_asset':
                       $name = "禁止打包资产";
                       $order = 11;
                        break;
                    case 'lending':
                       $name = "禁止放贷";
                       $order = 12;
                        break;
                    case 'offline':
                       $name = "禁止线下推广";
                       $order = 13;
                        break;
                    case 'announce':
                       $name = "信息披露完整";
                       $order = 14;
                        break;
                    case 'obj_info':
                       $name = "标的信息披露";
                       $order = 15;
                        break;    
                    case 'assure':
                       $name = "禁止自担保";
                       $order = 16;
                        break;
                    case 'safety':
                       $name = "信息系统安全评估";
                       $order = 17;
                        break;
                    // case 'sell':
                    //    $name = "禁止代销";
                    //     break;
                    case 'brenk':
                       $name = "无承诺保本保息";
                       $order = 18;
                        break;

                   
                    case 'product':
                       $name = "不代销理财产品";
                       $order = 19;
                        break;
                    
                    case 'business':
                       $name = "网贷中介营业执照";
                       $order = 20;
                        break;
                   
                    case 'telecom':
                       $name = "互金专属ICP经营许可证";
                       $order = 21;
                        break;
                    default:
                        # code...
                        break;
                }
                if($v==0){
                    $val = 1;
                }elseif ($v==1) {
                    $val = 2;
                }elseif ($v==2) {
                    $val = 3;
                }
                $arr[$i]['name'] = $name;
                $arr[$i]['val'] = $val;
                $arr[$i]['order'] = $order;
                $i = $i+1;
            }

        }
       $sort = array(  
        'direction' => 'SORT_ASC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序  
        'field'     => 'order',       //排序字段  
        ); 

         $arrSort = array();  
        foreach($arr AS $uniqid => $row){  
            foreach($row AS $key=>$value){  
                $arrSort[$key][$uniqid] = $value;  
            }  
        }  
        if($sort['direction']){  
            array_multisort($arrSort[$sort['field']],constant($sort['direction']),$arr);  
        }  

      //  print_r($arr);

        if($val_pass){
            $is_good = sprintf("%.0f",$is_good/$count*100);
            $cricel_course = array('info'=>$arr,'is_good'=>$is_good);
            $this->assign('cricel_course',$cricel_course);
            $content = $this->fetch('process_item');
            $this->ajaxReturn(array('content'=>$content));
        }else{
            $is_good = sprintf("%.0f",$is_good/$count*100);
            $cricel_course = array('info'=>$arr,'is_good'=>$is_good);
            return($cricel_course);
        }
        
    }

    /**
     * [push_list 平台投顾列表 按推荐成功的投资者数量排序]
     * @param  [type] $platform_id [平台ID]
     * @return [type]              [array]
     */
    public function push_list(){

        $platform_id = I('post.id');
        $user_id = I('post.userid');
        $map['id'] = $user_id;
        $user = D('User')->get_one($map);
        if($user){
            $map = array();
            $map['user_id'] = $user['referral'];
            $recom = D('Recommend')->get_one($map);
        }

        //圈子投顾
        $map = array();
        $map['platform_id'] = $platform_id;
        $push_list = D('RecommendPlatform')->get_all($map,$field='*',$page=0,$pagenum=3);
        $push_count = D('RecommendPlatform')->count($map);
        foreach ($push_list as $k => $v) {
            $map=array();
            $recommend_id = $v['recommend_id'];
            $map['id'] = $recommend_id;
            $recommen= D('Recommend')->get_one($map);
             if($v['recommend_id']==$recom['id']){
                $push_list[$k]['is_fans'] = 1;
            }else{
                $push_list[$k]['is_fans'] = 0;
            }

            $map = array();
            $map['id'] = $recommen['user_id'];
            $push_list[$k]['user']= D('User')->get_one($map);
            //统计推手在该平台投资人
            $map = array();
            $map['referral'] = $recommen['user_id'];
            $push_list[$k]['info'] = $recommen;
            $referral= D('User')->get_all($map);
            $tz_count = 0;
            foreach ($referral as $key => $value) {
                //print_r($value);
                $map = array();
                $map['user_id'] = $value['id'];
                $map['platform_id'] = $platform_id;
                $r = D('UserObject')->get_one($map);
                if($r){
                    ;
                     $tz_count = $tz_count+1;
                }
            }
            $push_list[$k]['tz_count'] =$tz_count;
            //红包
            $push_list[$k]['packet'] = R('Packet/get_redpacket',array('user_id'=>$recommen['user_id'],'platform_id'=>$platform_id));
        }

        $sort = array(  
        'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序  
        'field'     => 'tz_count',       //排序字段  
        ); 

         $arrSort = array();  
        foreach($push_list AS $uniqid => $row){  
            foreach($row AS $key=>$value){  
                $arrSort[$key][$uniqid] = $value;  
            }  
        }  
        if($sort['direction']){  
            array_multisort($arrSort[$sort['field']],constant($sort['direction']),$push_list);  
        }  
        $push_list = array_slice($push_list,0,7);
    //    $push_list = array('push_list'=>$push_list,'push_count'=>$push_count);
    //    print_r($push_list);
    //    print_r($push_count);die;
        if($push_list or $push_count) {
            $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>array('push_list'=>$push_list,'push_count'=>$push_count));
        } else {
            $res = array('errorCode'=>0,'msg'=>"暂无数据");
        }
        $this->ajaxReturn($res);
    }

    public function push_list_two(){

        $platform_id = I('post.id');
        $user_id = I('post.userid');
        $map['id'] = $user_id;
        $user = D('User')->get_one($map);
        if($user){
            $map = array();
            $map['user_id'] = $user['referral'];
            $recom = D('Recommend')->get_one($map);
        }

        //圈子投顾
        $map = array();
        $map['platform_id'] = $platform_id;
        $push_list = D('RecommendPlatform')->get_all($map,$field='*',$page=0,$pagenum=3);
        $push_count = D('RecommendPlatform')->count($map);
        foreach ($push_list as $k => $v) {
            $map=array();
            $recommend_id = $v['recommend_id'];
            $map['id'] = $recommend_id;
            $recommen= D('Recommend')->get_one($map);
             if($v['recommend_id']==$recom['id']){
                $push_list[$k]['is_fans'] = 1;
            }else{
                $push_list[$k]['is_fans'] = 0;
            }

            $map = array();
            $map['id'] = $recommen['user_id'];
            $push_list[$k]['user']= D('User')->get_one($map);
        }
            //圈子推荐明星投顾
             $maps = array();
             $maps['push_platform_id'] = $platform_id;
             $push_user= D('Recommend')->get_one($maps);
             //echo D('Recommend')->_sql();
             $maps = array();
             $maps['id'] = $push_user['user_id'];
             $push_user['user'] = D('User')->get_one($maps);
             $push_user['packet'] = R('Packet/get_redpacket',array('user_id'=>$push_user['user']['id'],'platform_id'=>$platform_id));

		
//print_r($push_list);die;
        $sort = array(  
        'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序  
        'field'     => 'tz_count',       //排序字段  
        ); 

         $arrSort = array();  
        foreach($push_list AS $uniqid => $row){  
            foreach($row AS $key=>$value){  
                $arrSort[$key][$uniqid] = $value;  
            }  
        }  
        if($sort['direction']){  
            array_multisort($arrSort[$sort['field']],constant($sort['direction']),$push_list);  
        }  
        $push_list = array_slice($push_list,0,7);
    //    $push_list = array('push_list'=>$push_list,'push_count'=>$push_count);
    //    print_r($push_list);
    //    print_r($push_count);die;
        if($push_list or $push_count) {
            $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>array('push_list'=>$push_list,'push_count'=>$push_count,'push_user'=>$push_user));
        } else {
            $res = array('errorCode'=>0,'msg'=>"暂无数据");
        }
        $this->ajaxReturn($res);
    }	
	
	


    /**
     * [get_appraisal 获取平台官方测评]
     * @param  [type] $platform_id [平台ID]
     * @return [type]              [array]
     */
    public function get_appraisal(){
        $platform_id = I('get.id');
        $map['id'] = $platform_id;
        $platform = D('Platform')->get_one($map,$field="id,name");
        $map = array();
        $map['platform_id'] = $platform_id;
        $video_app = M('VideoAppraisal')->where($map)->order('add_time desc')->select();
        if($video_app){
            foreach($video_app as $k => $v) {
                $video_app[$k]['add_time'] = date('Y-m-d',$v['add_time']);
                $house_id= $v['house_id'];
                $map = array();
                $map['id'] = $house_id;
                $video_app[$k]['video_info'] = D('Video')->get_one($map);

                if(!$house_id){
                    $map = array();
                    $map['id'] = $v['news_id'];
                    $video_app[$k]['news_info'] = D('NewsHouse')->get_one($map,$field="pic");
                    $video_app[$k]['house_id'] =0;
                   // echo D('NewsHouse')->_sql();
                }
                if($v['house_id'] == 574){
                    // unset($video_app[$k]);
                    $map = array();
                    $map['id'] = $v['news_id'];
                    $video_app[$k]['news_info'] = D('NewsHouse')->get_one($map,$field="pic");
                    $video_app[$k]['house_id'] =0;
                }

            }
        }
        if($video_app) {
            $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>$video_app,'platform'=>$platform['name']);
        } else {
            $res = array('errorCode'=>0,'msg'=>"暂无数据");
        }
        $this->ajaxReturn($res);

    }


    //第三方深度测评
    public function get_otth_appraisal(){
        $platform_id = I('get.id');
        $map['platform_id'] = $platform_id;
        $list = M('OtthAppraisal')->where($map)->limit(0,3)->select();
        foreach ($list as $k => $v) {
            $map = array();
            $map['id'] = $v['news_id'];
            $list[$k]['news_info'] = D('News')->get_one($map);
            $add_time = $list[$k]['news_info']['add_time'];
            $long = time()-$add_time;
            if($long<60){
                $list[$k]['add_date'] = $long."秒前";
            }else if($long<3600){
                $list[$k]['add_date'] = ceil($long/60)."分钟前";
            }else if($long<86400){
                $list[$k]['add_date'] = ceil($long/86400)."天前";
            }else if($long>86400){
                $list[$k]['add_date'] = date('Y-m-d H:i:s',$add_time);
            }else if($long=0){
                $list[$k]['add_date'] = "刚刚";
            }
        }
        if($list) {
            $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>$list);
        } else {
            $res = array('errorCode'=>0,'msg'=>"暂无数据");
        }
        $this->ajaxReturn($res);
    }




    /**
     * [get_evaluate 获取平台评价信息]
     * @param  [type] $platform_id [平台ID]
     * @return [type]              [array]
     */
    public function get_evaluate(){
        $platform_id = I('post.id');
        $p = I('post.currentPage');
        $pagenum=I('post.pageSize');
        $page = ($p-1)*$pagenum;

        //获取短评
        $map['platform_id'] = $platform_id;
        $map['user_role'] = 1;
        $map['status'] = 1;
        $pcomm1= D('PlatformCommentary')->get_all_page($map,$page,$pagenum);
        $map['user_role'] = 2;
        $pcomm2= D('PlatformCommentary')->get_all($map);
      // echo D('PlatformCommentary')->_sql();
        $pcomm=array_merge($pcomm1,$pcomm2);
        $userid = I('post.userid');
        foreach ($pcomm as $k => $v) {
            $v['tag'] = explode(',',$v['tag']);
            $map['id'] = $v['user_id'];
            $v['user'] =D('User')->get_one($map);
            $map = array();
            $map['user_id'] = $v['user_id'];
            $map['platform_id'] = $v['platform_id'];
            $v['grade'] = D('PlatformGrade')->get_one($map);

            $add_time = $v['add_time'];
            //判断是否点赞
            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 6;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $v['is_praise'] = 1;
                }else{
                    $v['is_praise'] = 0;
                }
            }else{
                    $v['is_praise'] = 0;
            }
            $long = time()-$add_time;

            if($long<60){
                $v['add_date'] = $long."秒前";
            }else if($long<3600){
                $v['add_date'] = ceil($long/60)."分钟前";
            }else if($long<86400){
                $v['add_date'] = ceil($long/86400)."天前";
            }else if($long>86400){
                $v['add_date'] = date('Y-m-d H:i:s',$add_time);
            }else if($long=0){
                 $v['add_date'] = "刚刚";
            }


            if($v['user_role']==1){
                $evaluate_list['user_evaluate'][] = $v;
            }elseif($v['user_role']==2){
                $v['type']=1;
                $push_evaluate[]= $v;
            }
        }
        //合并推手的深度评测
        $map = array();
        $map['platform_id'] = $platform_id;
        $map['status'] = 1;
        $depth = D('Depth')->get_all($map);
        foreach ($depth as $k => $v) {
            $map = array();
            $map['user_id'] = $v['user_id'];
            $map['platform_id'] = $v['platform_id'];
            $v['grade'] = D('PlatformGrade')->get_one($map);
            $v['type']=2;
             if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 7;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $v['is_praise'] = 1;
                }else{
                    $v['is_praise'] = 0;
                }
            }else{
                    $v['is_praise'] = 0;
            }
             $push_evaluate[]= $v;
        }
        //合并信批
        $map = array();
        $map['platform_id'] = $platform_id;
        $map['status'] = 1;
        $announce = D('CircleAnnounce')->get_all($map);
        foreach ($announce as $k => $v) {
            $map = array();
            $map['user_id'] = $v['user_id'];
            $map['platform_id'] = $v['platform_id'];
            $v['grade'] = D('PlatformGrade')->get_one($map);
            $v['type']=3;

             if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 9;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $v['is_praise'] = 1;
                }else{
                    $v['is_praise'] = 0;
                }
            }else{
                    $v['is_praise'] = 0;
            }
            $push_evaluate[]= $v;
        }
        //合并舆情解读
        $map = array();
        $map['platform_id'] = $platform_id;
        $map['status'] = 1;
        $opinion = D('CircleOpinion')->get_all($map);
        foreach ($opinion as $k => $v) {
            $map = array();
            $map['user_id'] = $v['user_id'];
            $map['platform_id'] = $v['platform_id'];
            $v['grade'] = D('PlatformGrade')->get_one($map);
            $v['type']=4;

            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 8;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $v['is_praise'] = 1;
                }else{
                    $v['is_praise'] = 0;
                }
            }else{
                    $v['is_praise'] = 0;
            }
            $push_evaluate[]= $v;

        }
    //    print_r($push_evaluate);die;
        foreach ($push_evaluate as $k => $v) {
            
            $map = array();
            $map['id'] = $v['user_id'];
            $push_evaluate[$k]['user'] =D('User')->get_one($map);
            $add_time = $v['add_time'];

            $long = time()-$add_time;
           
            if($long<60){
                $push_evaluate[$k]['add_date'] = $long."秒前";
            }else if($long<3600){
                $push_evaluate[$k]['add_date'] = ceil($long/60)."分钟前";
            }else if($long<86400){
                $push_evaluate[$k]['add_date'] = ceil($long/86400)."天前";
            }else if($long>86400){
                $push_evaluate[$k]['add_date'] = date('Y-m-d H:i:s',$add_time);
            }else if($long=0){
                $push_evaluate[$k]['add_date'] = "刚刚";
            }
        }

        //时间排序
        $sort = array(
        'direction' => 'SORT_DESC', //排序顺序标志 SORT_DESC 降序；SORT_ASC 升序
        'field'     => 'add_time',       //排序字段
        );

        $arrSort = array();
        foreach($push_evaluate AS $uniqid => $row){
            foreach($row AS $key=>$value){
                $arrSort[$key][$uniqid] = $value;
            }
        }
        if($sort['direction']){
            array_multisort($arrSort[$sort['field']],constant($sort['direction']),$push_evaluate);
        }
        $push_evaluate=array_slice($push_evaluate,$page,$pagenum);
        $evaluate_list['push_evaluate'] = $push_evaluate;

        if($evaluate_list) {
            $res = array('errorCode'=>1,'msg'=>"获取成功",'data'=>$evaluate_list);
        } else {
            $res = array('errorCode'=>0,'msg'=>"暂无数据");
        }
        $this->ajaxReturn($res);
    }


    /**
     * [get_program_tag 获取平台圈子基础信息]
     * @param  [type] $platform_id [description]
     * @return [type]              [description]
     */
    public function get_program_circle($platform_id){
        $map['platform_id'] = $platform_id;
        $info = D('Circle')->get_one($map);
        return $info;
    }


    /**
     * [grade 提交平台综合评价]
     * @return [type] [description]
     */
    public function grade(){
        $user_id = I('post.userid');
        $map['id'] = $user_id;
        $userinfo = D('User')->get_one($map);
        $user_role = $userinfo['role'];
        if($user_role==2){
            $role = 2;
        }else{
            $role = 1;
        }
        $platform_id = I('post.id');
        $colligate = I('post.colligate');
        $is_invest = I('post.is_invest');
        $map = array();
        $map['platform_id'] = $platform_id;
        $map['user_id'] = $user_id;
        $r = D('PlatformGrade')->get_one($map);
        if($r){
            $map = array();
            $map['platform_id'] = $platform_id;
            $map['user_id'] = $user_id;
            $data['colligate'] = $colligate;
            $data['is_invest'] = $is_invest;
            $data['user_role'] = $role;
            $res = D('PlatformGrade')->edit($map,$data);
        }else{
            $data['user_id'] = $user_id;
            $data['user_role'] = $role;
            $data['colligate'] = $colligate;
            $data['is_invest'] = $is_invest;
            $data['platform_id'] = $platform_id;
            $data['add_time'] = time();
            $res = D('PlatformGrade')->add($data);
        }
        if($res){
            $data = array('errorCode'=>1,'msg'=>"获取成功！",'data'=>$res);
        }else{
            $data = array('errorCode'=>0,'msg'=>"您未作出任何修改");

        }
        $this->ajaxReturn($data);
    }
    /**
     * [add_commentary 添加平台短评]
     */
    public function short_commentary(){
            $edit = I('post.edit');
            if($edit){
                $user_id = I('post.userid');
                $info_id = I('post.info_id');
                $map['id'] = $info_id;
                $info = D('PlatformCommentary')->get_one($map);
                if($info['user_id']==$user_id){
                    $datas['id'] =$info_id;
                    $tag = I('post.tag');
                    $datas['tag'] = implode(',',$tag);
                    $datas['evaluate'] = I('post.evaluate');
                    $map = array();
                    $map['id'] = $info_id;
                    $r = D('PlatformCommentary')->edit($map,$datas);
                    if($r){
                        $data = array('errorCode'=>1,'msg'=>"编辑成功");
                    }else{
                        $data = array('errorCode'=>0,'msg'=>"您未修改任何内容");
                    }
                    $this->ajaxReturn($data);
                }else{
                    $data = array('errorCode'=>2,'msg'=>"非法操作");
                    $this->ajaxReturn($data);
                }
               
            }
            $user_id = I('post.userid');
            $map['id'] = $user_id;
            $user = D('User')->get_one($map);
            $user_role = $user['role'];
            $card_status = $user['card_status'];
            if($card_status==0){
                $data = array('errorCode'=>2,'msg'=>"您未实名认证提交失败！");
                $this->ajaxReturn($data);
            }
            $tag = I('post.tag');
            $data['tag'] = implode(',',$tag);
            $data['evaluate'] = I('post.evaluate');
            $data['platform_id'] = I('post.id');
            $data['user_id'] =$user_id;
            if($user_role==2){
                $data['user_role']=2;
            }else{
                $data['user_role']=1;
            }
            $data['status']=1;
            $data['add_time']=time();
            $r = D('PlatformCommentary')->add($data);
           //echo  D('PlatformCommentary')->_sql();
            if($r){
                $data = array('errorCode'=>1,'msg'=>"提交成功！");
            }else{
                $data = array('errorCode'=>0,'msg'=>"提交失败！");
            }
            $this->ajaxReturn($data);

    }
    /**
     * [commentary_info 短评详情]
     * @return [type] [description]
     */
    public function commentary_info(){
        $id = I('post.id');
        $platform_id = I('post.platform_id');
        $userid = I('post.userid');
        $map['id'] = $id;
        $info = D('PlatformCommentary')->get_one($map);
        $map = array();
        $map['id'] = $info['user_id'];
        $info['user'] = D('User')->get_one($map);
        $info['tag'] = explode(',',$info['tag']);

        if($userid){
            $where['id_user'] = $userid;
            $where['type'] = 6;
            $where['id_target'] = $info['id'];
            $praise = D('Praise')->get_one($where);
            if($praise){
                $info['is_praise'] = 1;
            }else{
                $info['is_praise'] = 0;
            }
        }else{
            $info['is_praise'] = 0;
        }

            $long = time()-$info['add_time'];
            if($long<60){
                $info['add_date'] = $long."秒前";
            }else if($long<3600){
                $info['add_date'] = ceil($long/60)."分钟前";
            }else if($long<86400){
                $info['add_date'] = ceil($long/86400)."天前";
            }else if($long>86400){
                $info['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
            }else if($long=0){
                 $info['add_date'] = "刚刚";
            }




         //查询用户综合评价
         $map = array();
         $map['user_id'] = $info['user_id'];
         $map['platform_id'] = $platform_id;
         $grade = D('PlatformGrade')->get_one($map);
        //   echo D('PlatformGrade')->_sql();
        // print_r($grade);die;
        //查询评论
        $map = array();
        $map['id_target'] = $id;
        $map['type'] = 4;
        $map['p_id'] =0;
        $comment = D('Comment')->get_all($map);
       
        foreach ($comment as $k => $v) {
             $long = time()-$v['add_time'];
            if($long<60){
                $comment[$k]['add_date'] = $long."秒前";
            }else if($long<3600){
                $comment[$k]['add_date'] = ceil($long/60)."分钟前";
            }else if($long<86400){
                $comment[$k]['add_date'] = ceil($long/86400)."天前";
            }else if($long>86400){
                $comment[$k]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
            }else if($long=0){
                $comment[$k]['add_date'] = "刚刚";
            }

            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 3;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
             if($praise){
                    $comment[$k]['is_praise'] = 1;
                }else{
                    $comment[$k]['is_praise'] = 0;
                }
            }else{
                    $comment[$k]['is_praise'] = 0;
            }


            $map = array();
            $map['id'] = $v['user_id'];
            $comment[$k]['user'] = D('User')->get_one($map);
            $map = array();
            $map['p_id'] =$v['id'];
            $kid = D('Comment')->get_all($map);
                foreach ($kid as $ke => $va) {
                    $map = array();
                    $map['id'] = $va['user_id'];
                    $kid[$ke]['user'] = D('User')->get_one($map);
                    $long = time()-$va['add_time'];
                    if($long<60){
                         $kid[$ke]['add_date'] = $long."秒前";
                    }else if($long<3600){
                         $kid[$ke]['add_date'] = ceil($long/60)."分钟前";
                    }else if($long<86400){
                         $kid[$ke]['add_date'] = ceil($long/86400)."天前";
                    }else if($long>86400){
                         $kid[$ke]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
                    }else if($long=0){
                         $kid[$ke]['add_date'] = "刚刚";
                    }


                }
            $comment[$k]['kid'] = $kid;
        }
        if($grade or $comment or $info){
            $data = array('errorCode'=>1,'msg'=>"获取成功！",'data'=>array('grade'=>$grade,'comment'=>$comment,'info'=>$info));
        }else{
            $data = array('errorCode'=>0,'msg'=>"暂无数据！");
        }
            $this->ajaxReturn($data);
    }


    /**
     * [circle_opinion_info 舆情详情]
     * @return [type] [description]
     */
    public function circle_opinion_info(){
        $id = I('post.id');
        $platform_id = I('post.platform_id');
        $userid = I('post.userid');
        $map['id'] = $id;
        $info = D('CircleOpinion')->get_one($map);
        $map = array();
        $map['id'] = $info['user_id'];
        $info['user'] = D('User')->get_one($map);
        $info['tag'] = explode(',',$info['tag']);

        if($userid){
            $where['id_user'] = $userid;
            $where['type'] = 8;
            $where['id_target'] = $info['id'];
            $praise = D('Praise')->get_one($where);
            //echo D('Praise')->_sql();
            if($praise){
                $info['is_praise'] = 1;
                }else{
                    $info['is_praise'] = 0;
                }
            }else{
                    $info['is_praise'] = 0;
            }

            $long = time()-$info['add_time'];
            if($long<60){
                $info['add_date'] = $long."秒前";
            }else if($long<3600){
                $info['add_date'] = ceil($long/60)."分钟前";
            }else if($long<86400){
                $info['add_date'] = ceil($long/86400)."天前";
            }else if($long>86400){
                $info['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
            }else if($long=0){
                 $info['add_date'] = "刚刚";
            }




         //查询用户综合评价
         $map = array();
         $map['user_id'] = $info['user_id'];
         $map['platform_id'] = $platform_id;
         $grade = D('PlatformGrade')->get_one($map);
        //   echo D('PlatformGrade')->_sql();
        // print_r($grade);die;
        //查询评论
        $map = array();
        $map['id_target'] = $id;
        $map['type'] = 6;
        $map['p_id'] =0;
        $comment = D('Comment')->get_all($map);
    //   print_r($comment);die;
        foreach ($comment as $k => $v) {
             $long = time()-$v['add_time'];
            if($long<60){
                $comment[$k]['add_date'] = $long."秒前";
            }else if($long<3600){
                $comment[$k]['add_date'] = ceil($long/60)."分钟前";
            }else if($long<86400){
                $comment[$k]['add_date'] = ceil($long/86400)."天前";
            }else if($long>86400){
                $comment[$k]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
            }else if($long=0){
                $comment[$k]['add_date'] = "刚刚";
            }

            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 3;
                $where['id_target'] = $v['id'];
                $praise = D('Praise')->get_one($where);
             if($praise){
                    $comment[$k]['is_praise'] = 1;
                }else{
                    $comment[$k]['is_praise'] = 0;
                }
            }else{
                    $comment[$k]['is_praise'] = 0;
            }


            $map = array();
            $map['id'] = $v['user_id'];
            $comment[$k]['user'] = D('User')->get_one($map);
            $map = array();
            $map['p_id'] =$v['id'];
            $kid = D('Comment')->get_all($map);
                foreach ($kid as $ke => $va) {
                    $map = array();
                    $map['id'] = $va['user_id'];
                    $kid[$ke]['user'] = D('User')->get_one($map);
                    //echo 
                    $long = time()-$va['add_time'];
                    if($long<60){
                         $kid[$ke]['add_date'] = $long."秒前";
                    }else if($long<3600){
                         $kid[$ke]['add_date'] = ceil($long/60)."分钟前";
                    }else if($long<86400){
                         $kid[$ke]['add_date'] = ceil($long/86400)."天前";
                    }else if($long>86400){
                         $kid[$ke]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
                    }else if($long=0){
                         $kid[$ke]['add_date'] = "刚刚";
                    }


                }
            $comment[$k]['kid'] = $kid;
        }


        if($grade or $comment or $info){
            $data = array('errorCode'=>1,'msg'=>"获取成功！",'data'=>array('grade'=>$grade,'comment'=>$comment,'info'=>$info));
        }else{
            $data = array('errorCode'=>0,'msg'=>"暂无数据！");
        }
            $this->ajaxReturn($data);
    }

    /**
     * [depth 提交深度测评]
     * @return [type] [description]
     */
    public function depth(){
        if(IS_POST) {
            $user_id = I('post.userid');
            $temporary = I('post.temporary');//0发布  1草稿
            $platform_id = I('post.platform_id');
            $edit = I('post.edit');
            if($edit) {
                $info_id = I('post.info_id');
                $map['id'] = $info_id;
                $d_info = D('Depth')->get_one($map);
                if($d_info['user_id']==$user_id) {
                    $maps['id'] = $info_id;
                    $datas = I('post.');
                    unset($datas['temporary']);
                    unset($datas['userid']);
                    unset($datas['info_id']);
                    unset($datas['edit']);
                    $res = D('Depth')->edit($maps,$datas);
                    if($res){
                        $arr = array('errorCode'=>1,'msg'=>'编辑成功');
                    }else{
                        $arr = array('errorCode'=>0,'msg'=>'编辑失败');
                    }
                     $this->ajaxReturn($arr);
                }else{
                    $data = array('errorCode'=>2,'msg'=>"非法操作");
                    $this->ajaxReturn($data);
                }
            }
            if($temporary==1){
                $filed = I('post.filed');   //判断暂存
                $map['user_id'] = $user_id;
                $map['platform_id'] = $platform_id;
                $map['status'] = 0;
                $r = D('Depth')->get_one($map);
                if($r){

                    $data[$filed] = I('post.name');
                    
                    $map = array();
                    $map['user_id'] = $user_id;
                    $map['platform_id'] = $platform_id;
                    $map['status'] = 0;
                    $res = D('Depth')->edit($map,$data);
                    if($res){
                        $arr = array('errorCode'=>1,'msg'=>'暂存成功','data'=>$res);
                    }else{
                        $arr = array('errorCode'=>0,'msg'=>'暂存失败');
                    }
                }else{
                    $data = array();
                    $data[$filed] = I('post.name');
                    $data['user_id'] = $user_id;
                    $data['platform_id'] = $platform_id;
                //    $data['add_time'] = $add_time;
                    $map['status'] = 0;
                    $res = D('Depth')->add($data);
                    if($res){
                        $arr = array('errorCode'=>1,'msg'=>'暂存成功','data'=>$res);
                    }else{
                        $arr = array('errorCode'=>0,'msg'=>'暂存失败');
                    }
                }
                $this->ajaxReturn($arr);
            }else{
                $postdata = I('post.');
                $postdata['add_time'] = time();
                $postdata['user_id'] = $postdata['userid'];
                unset($postdata['userid']);
            //    print_r($postdata);die;
                unset($postdata['temporary']);
                $postdata['status'] = 1;
                $map = array();
                $map['user_id'] = $user_id;
                $map['platform_id'] = $platform_id;
                $map['status'] = 0;
                $r = D('Depth')->get_one($map);
                if($r){
                    $map = array();
                    $map['user_id'] = $user_id;
                    $map['platform_id'] = $platform_id;
                    $map['status'] = 0;
                //    print_r($postdata);die;
                    $res = D('Depth')->edit($map,$postdata);
                    if($res){
                        $arr = array('errorCode'=>1,'msg'=>'发表成功');
                    }else{
                        $arr = array('errorCode'=>0,'msg'=>'发表失败');
                    }
                }else{
                    $res = D('Depth')->add($postdata);
                    if($res){
                        $arr = array('errorCode'=>1,'msg'=>'发表成功');
                    }else{
                        $arr = array('errorCode'=>0,'msg'=>'发表失败');
                    }
                }

                $this->ajaxReturn($arr);
            }
        } else {

            $platform_id = I('get.id');
            $map['platform_id'] = $platform_id;
            $info = D('PlatformParameters')->get_one($map);
            $user_id = I('get.userid');
            $map['platform_id'] = $platform_id;
            $map['user_id'] = $user_id;
            $r = D('PlatformGrade')->get_one($map);

            $map = array();
            $map['user_id'] = $user_id;
            $map['platform_id'] = $platform_id;
            $map['status'] = 0;
            $res = D('Depth')->get_one($map);

            //管理团队
            $map['platform_id'] = $platform_id;
            $plat_team = M('PlatformTeam')->where($map)->select();

            //股权结构
            $plat_stock = M('PlatformStock')->where($map)->select();

            //资产类型
            $platform_assets = M('PlatformAssets')->where($map)->select();
            //舆情
            $platform_opinion = M('PlatformOpinion')->where($map)->select();
            $opinion_count = M('PlatformOpinion')->where($map)->count();

            if($res or $r or $info or $plat_team or $plat_stock or $platform_assets or $platform_opinion or $opinion_count){
                $arr = array('errorCode'=>1,'msg'=>"获取成功！",'data'=>array('res'=>$res,'r'=>$r['colligate'],'info'=>$info,'plat_team'=>$plat_team,'plat_stock'=>$plat_stock,'platform_assets'=>$platform_assets,'platform_opinion'=>$platform_opinion,'opinion_count'=>$opinion_count));
            }else{
                $arr = array('errorCode'=>0,'msg'=>"暂无数据！");
            }
                $this->ajaxReturn($arr);
        }


    }

    /**
     * [depth_info 深度测评详情]
     * @return [type] [description]
     */
    public function depth_info(){

            $platform_id = I('post.platform_id');
            $map['platform_id'] = $platform_id;
            $info = D('PlatformParameters')->get_one($map);
           // echo D('PlatformParameters')->_sql();
            $user_id = I('post.userid');
            $map['platform_id'] = $platform_id;
            $map['user_id'] = $user_id;
            $r = D('PlatformGrade')->get_one($map);

            $map = array();
            $map['user_id'] = I('post.userid');
            $map['platform_id'] = $platform_id;
            $map['status'] = 0;
            $res = D('Depth')->get_one($map);
			$map = array();
            //管理团队
            $map['platform_id'] = $platform_id;
            $plat_team = M('PlatformTeam')->where($map)->select();

            //股权结构

            $plat_stock = M('PlatformStock')->where($map)->select();
            //资产类型
            $platform_assets = M('PlatformAssets')->where($map)->select();
            //舆情
            $platform_opinion = M('PlatformOpinion')->where($map)->select();
            $opinion_count = M('PlatformOpinion')->where($map)->count();

            //解读
            $map = array();
            $map['id'] = I('post.id');
            $r = D('Depth')->get_one($map);
            $user_id = $r['user_id'];
            $map['id'] = $user_id;
            $r['user'] =D('User')->get_one($map);
            $long = time()-$r['add_time'];

            if($long<60){
                $r['add_date'] = $long."秒前";
            }else if($long<3600){
                $r['add_date'] = ceil($long/60)."分钟前";
            }else if($long<86400){
                $r['add_date'] = ceil($long/86400)."天前";
            }else if($long>86400){
                $r['add_date'] = date('Y-m-d H:i:s',$add_time);
            }else if($long=0){
                $r['add_date'] = "刚刚";
            }
              //查询用户综合评价
             $map = array();
             $map['user_id'] =  $user_id;
             $map['platform_id'] = $platform_id;
             $grade = D('PlatformGrade')->get_one($map);
            //判断点赞
            $userid = I('post.userid');
            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 7;
                $where['id_target'] = I('post.id');
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $r['is_praise'] = 1;
                }else{
                    $r['is_praise'] = 0;
                }
            }else{
                    $r['is_praise'] = 0;
            }

                //查询评论
            $map = array();
            $map['id_target'] = I('post.id');
            $map['type'] = 5;
            $map['p_id'] =0;
            $comment = D('Comment')->get_all($map);

            foreach ($comment as $k => $v) {
                 $long = time()-$v['add_time'];
                if($long<60){
                    $comment[$k]['add_date'] = $long."秒前";
                }else if($long<3600){
                    $comment[$k]['add_date'] = ceil($long/60)."分钟前";
                }else if($long<86400){
                    $comment[$k]['add_date'] = ceil($long/86400)."天前";
                }else if($long>86400){
                    $comment[$k]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
                }else if($long=0){
                    $comment[$k]['add_date'] = "刚刚";
				}

				if($userid){
					$where['id_user'] = $userid;
					$where['type'] = 3;
					$where['id_target'] = $v['id'];
					$praise = D('Praise')->get_one($where);
					if($praise){
						$comment[$k]['is_praise'] = 1;
					}else{
						$comment[$k]['is_praise'] = 0;
					}
				}else{
						$comment[$k]['is_praise'] = 0;
				}


				$map = array();
				$map['id'] = $v['user_id'];
				$comment[$k]['user'] = D('User')->get_one($map);
				$map = array();
				$map['p_id'] =$v['id'];
				$kid = D('Comment')->get_all($map);
					foreach ($kid as $ke => $va) {
						$map = array();
						$map['id'] = $va['user_id'];
						$kid[$ke]['user'] = D('User')->get_one($map);
						//echo 
						$long = time()-$va['add_time'];
						if($long<60){
							 $kid[$ke]['add_date'] = $long."秒前";
						}else if($long<3600){
							 $kid[$ke]['add_date'] = ceil($long/60)."分钟前";
						}else if($long<86400){
							 $kid[$ke]['add_date'] = ceil($long/86400)."天前";
						}else if($long>86400){
							 $kid[$ke]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
						}else if($long=0){
							 $kid[$ke]['add_date'] = "刚刚";
						}


					}
                    $comment[$k]['kid'] = $kid;
            }
            //    print_r($platform_assets);die;
            if($platform_assets && $plat_stock && $plat_team && $info) {
                $result = array('errorCode'=>1,'msg'=>"获取成功",'res'=>$r,'grade'=>$grade,'opinion_count'=>$opinion_count,'platform_opinion'=>$platform_opinion,'platform_assets'=>$platform_assets,'plat_stock'=>$plat_stock,'plat_team'=>$plat_team,'info'=>$info,'colligate'=>$r['colligate'],'comment'=>$comment);
            } else {
                $result = array('errorCode'=>0,'msg'=>"暂无数据");
            }
            $this->ajaxReturn($result);
    }

    public function infoann(){
        if(IS_POST){
            $user_id = I('post.userid');
            $edit = I('post.edit');
            if($edit == 1){
                $info_id = I('post.info_id');
                $map['id'] = $info_id;
                $f_info = D('CircleAnnounce')->get_one($map);
                if($f_info['user_id']==$user_id){
                    $datas['announce'] = I('post.announce');
                    $maps['id'] = $info_id;
                    $r = D('CircleAnnounce')->edit($maps,$datas);
                    if($r){
                        $arr = array('errorCode'=>1,'msg'=>'编辑成功');
                    }else{
                        $arr = array('errorCode'=>0,'msg'=>'编辑失败');
                    }
                    $this->ajaxReturn($arr);
                }else{
                    $arr = array('errorCode'=>2,'msg'=>'非法操作');
                    $this->ajaxReturn($arr);
                }
                
            }
            $postdata['user_id'] = I('post.userid');
            $postdata['platform_id'] = I('post.platform_id');
            $postdata['announce'] = I('post.announce');
            $postdata['status'] = 1;
            $postdata['add_time'] = time();
            $r = D('CircleAnnounce')->add($postdata);
            if($r){
                $arr = array('errorCode'=>1,'msg'=>'发表成功');
            }else{
                $arr = array('errorCode'=>0,'msg'=>'发表失败');
            }
            $this->ajaxReturn($arr);
        }else{
            $id = I('get.id');
            $map['platform_id'] = $id;
            $infos = D('CircleInfoann')->get_one($map);
          
            foreach ($infos as $k => $v) {
                //平台基础信息
                $info['basics']['plat_name'] = $infos['plat_name'];//平台全称及简称 
                $info['basics']['plat_add'] = $infos['plat_add'];//平台注册地址  
                $info['basics']['capital'] = $infos['capital'];//平台注册资本和实缴资本 
                $info['basics']['online'] = $infos['online'];//平台成立时间
                $info['basics']['legal'] = $infos['legal'];//平台法定代表人
                $info['basics']['treaty'] = $infos['treaty'];//注册协议模板 
                $info['basics']['branch'] = $infos['branch'];//平台及其各分支机构经营场所
                $info['basics']['deposit'] = $infos['deposit'];//客户资金存管情况
                $info['basics']['perm'] = $infos['perm'];//相应电信业务经营许可信息
                $info['basics']['evals'] = $infos['eval'];//信息安全评测认证信息
                $info['basics']['scope'] = $infos['scope'];//平台经营范围 
                $info['basics']['records'] = $infos['records'];//地方金融监管部门备案登记信息
                $info['basics']['insure'] = $infos['insure'];//与保险机构，担保机构等合作情况
                //平台治理信息
                $info['govern']['tissue'] = $infos['tissue'];//组织机构 
                $info['govern']['control'] = $infos['control'];//实际控制人持股名单
                $info['govern']['director'] = $infos['director'];//董事，监事
                //平台财务
                $info['finance']['audit'] = $infos['audit'];//审计报告意见
                $info['finance']['financing'] = $infos['financing'];//重要融资信息 
                //运营信息
                $info['operate']['trade'] = $infos['trade'];//交易金额 
                $info['operate']['stroke'] = $infos['stroke'];//交易总笔数
                $info['operate']['borrow'] = $infos['borrow'];//借款人总数 
                $info['operate']['invest'] = $infos['invest'];//投资人总数 
                $info['operate']['compen'] = $infos['compen'];//代偿金额
                $info['operate']['exceed'] = $infos['exceed'];//逾期金额
                $info['operate']['limit'] = $infos['limit'];//项目逾期率
                $info['operate']['limit_num'] = $infos['limit_num'];//逾期项目数 
                $info['operate']['pre_borrow'] = $infos['pre_borrow'];//人均累计借款金额
                $info['operate']['pre_invest'] = $infos['pre_invest'];//人均累计投资金额
                $info['operate']['single_finan'] = $infos['single_finan'];//单笔均融资金额 
                $info['operate']['one_balance'] = $infos['one_balance'];//最大单户借款余额占比   
                $info['operate']['ten_balance'] = $infos['ten_balance'];//最大10户借款余额占比
                $info['operate']['one_invest'] = $infos['one_invest'];//最大单户投资余额占比
                $info['operate']['ten_invest'] = $infos['ten_invest'];//最大十户投资余额占比
                $info['operate']['history'] = $infos['history'];//历史逾期项目数
                $info['operate']['add_borrow'] = $infos['add_borrow'];//人均累计借款金额
                $info['operate']['add_invest'] = $infos['add_invest'];//人均累计投资额度
                $info['operate']['mean_invest'] = $infos['mean_invest'];//单笔均融资金额
                //项目简介
                
                $info['obj']['project'] = $infos['project'];    //项目简介
                $info['obj']['guarantee'] = $infos['guarantee'];//还款保障措施
                $info['obj']['risk'] = $infos['risk'];//项目风险提示
                $info['obj']['useing'] = $infos['use'];//借款用途
                $info['obj']['cost'] = $infos['cost'];//相关费用 
                $info['obj']['contract'] = $infos['contract'];//合同模板 
                $info['obj']['project_info'] = $infos['project_info'];//项目基础信息
                
            }
            $basics_i = 0;
            $basics_count = count($info['basics']);
            foreach ($info['basics'] as $k => $v) {
                if($v==1){
                    $basics_i = $basics_i+1;
                }
                $info['basics']['v'] = ceil($basics_i/$basics_count*100);
            }

            $finance_i = 0;
            $finance_count = count($info['finance']);
            foreach ($info['finance'] as $k => $v) {
                if($v==1){
                    $finance_i = $finance_i+1;
                }
                $info['finance']['v'] = ceil($finance_i/$finance_count*100);
            }

            $govern_i = 0;
            $govern_count = count($info['govern']);
            foreach ($info['govern'] as $k => $v) {
                if($v==1){
                    $govern_i = $govern_i+1;
                }
                $info['govern']['v'] = ceil($govern_i/$govern_count*100);
            }

            $operate_i = 0;
            $operate_count = count($info['operate']);
            foreach ($info['operate'] as $k => $v) {
                if($v==1){
                    $operate_i = $operate_i+1;
                }
                $info['operate']['v'] = ceil($operate_i/$operate_count*100);
            }

            $obj_i = 0;
            $obj_count = count($info['obj']);
            foreach ($info['obj'] as $k => $v) {
                if($v==1){
                    $obj_i = $obj_i+1;
                }
                $info['obj']['v'] = ceil($obj_i/$obj_count*100);
            }

            $infos_i = 0;
            $infos_count = count($infos);
            foreach ($infos as $k => $v) {
                if($v==1){
                    $infos_i = $infos_i+1;
                }
                $infos['v'] = ceil($infos_i/$infos_count*100);
            }

            $map = array();
            $user_id = I('get.userid');
            $platform_id =I('get.id');
            $map['platform_id'] = $platform_id;
            $map['user_id'] = $user_id;
            $r = D('PlatformGrade')->get_one($map);//平台总的评价
        //    echo D('PlatformGrade')->_sql();die;
            if($infos or $r or $info){
                $arr = array('errorCode'=>1,'msg'=>"获取成功！",'data'=>array('r'=>$r['colligate'],'info'=>$info,'infos'=>$infos['v']));
            }else{
                $arr = array('errorCode'=>0,'msg'=>"暂无数据！");
            }
                $this->ajaxReturn($arr);

        }

    }


    /**
     * [infoann_info 信批详情]
     * @return [type] [description]
     */
     public function infoann_info(){

            $id = I('post.platform_id');
            $map['platform_id'] = $id;
            $infos = D('CircleInfoann')->get_one($map);
            $map = array();
            $map['id'] = $id;
            $platform_info = D('Platform')->get_one($map);
            $infos['platform_name'] = $platform_info['name'];
            $map = array();
            $map['platform_id'] = $id;
            $platform_report = M('PlatformReport')->where($map)->order('id desc')->find(); //平台月报报告

            foreach ($infos as $k => $v) {
                //平台基础信息
                $info['basics']['plat_name'] = $infos['plat_name'];//平台全称及简称 
                $info['basics']['plat_add'] = $infos['plat_add'];//平台注册地址  
                $info['basics']['capital'] = $infos['capital'];//平台注册资本和实缴资本 
                $info['basics']['online'] = $infos['online'];//平台成立时间
                $info['basics']['legal'] = $infos['legal'];//平台法定代表人
                $info['basics']['treaty'] = $infos['treaty'];//注册协议模板 
                $info['basics']['branch'] = $infos['branch'];//平台及其各分支机构经营场所
                $info['basics']['deposit'] = $infos['deposit'];//客户资金存管情况
                $info['basics']['perm'] = $infos['perm'];//相应电信业务经营许可信息
                $info['basics']['evals'] = $infos['eval'];//信息安全评测认证信息
                $info['basics']['scope'] = $infos['scope'];//平台经营范围 
                $info['basics']['records'] = $infos['records'];//地方金融监管部门备案登记信息
                $info['basics']['insure'] = $infos['insure'];//与保险机构，担保机构等合作情况
                //平台治理信息
                $info['govern']['tissue'] = $infos['tissue'];//组织机构 
                $info['govern']['control'] = $infos['control'];//实际控制人持股名单
                $info['govern']['director'] = $infos['director'];//董事，监事
                //平台财务
                $info['finance']['audit'] = $infos['audit'];//审计报告意见
                $info['finance']['financing'] = $infos['financing'];//重要融资信息 
                //运营信息
                $info['operate']['trade'] = $infos['trade'];//交易金额 
                $info['operate']['stroke'] = $infos['stroke'];//交易总笔数
                $info['operate']['borrow'] = $infos['borrow'];//借款人总数 
                $info['operate']['invest'] = $infos['invest'];//投资人总数 
                $info['operate']['compen'] = $infos['compen'];//代偿金额
                $info['operate']['exceed'] = $infos['exceed'];//逾期金额
                $info['operate']['limit'] = $infos['limit'];//项目逾期率
                $info['operate']['limit_num'] = $infos['limit_num'];//逾期项目数 
                $info['operate']['pre_borrow'] = $infos['pre_borrow'];//人均累计借款金额
                $info['operate']['pre_invest'] = $infos['pre_invest'];//人均累计投资金额
                $info['operate']['single_finan'] = $infos['single_finan'];//单笔均融资金额 
                $info['operate']['one_balance'] = $infos['one_balance'];//最大单户借款余额占比   
                $info['operate']['ten_balance'] = $infos['ten_balance'];//最大10户借款余额占比
                $info['operate']['one_invest'] = $infos['one_invest'];//最大单户投资余额占比
                $info['operate']['ten_invest'] = $infos['ten_invest'];//最大十户投资余额占比
                $info['operate']['history'] = $infos['history'];//历史逾期项目数
                $info['operate']['add_borrow'] = $infos['add_borrow'];//人均累计借款金额
                $info['operate']['add_invest'] = $infos['add_invest'];//人均累计投资额度
                $info['operate']['mean_invest'] = $infos['mean_invest'];//单笔均融资金额
                //项目简介
                
                $info['obj']['project'] = $infos['project'];    //项目简介
                $info['obj']['guarantee'] = $infos['guarantee'];//还款保障措施
                $info['obj']['risk'] = $infos['risk'];//项目风险提示
                $info['obj']['useing'] = $infos['use'];//借款用途
                $info['obj']['cost'] = $infos['cost'];//相关费用 
                $info['obj']['contract'] = $infos['contract'];//合同模板 
                $info['obj']['project_info'] = $infos['project_info'];//项目基础信息
                
            }
            $basics_i = 0;
            $basics_count = count($info['basics']);
            foreach ($info['basics'] as $k => $v) {
                if($v==1){
                    $basics_i = $basics_i+1;
                }
                $info['basics']['v'] = ceil($basics_i/$basics_count*100);
            }

            $finance_i = 0;
            $finance_count = count($info['finance']);
            foreach ($info['finance'] as $k => $v) {
                if($v==1){
                    $finance_i = $finance_i+1;
                }
                $info['finance']['v'] = ceil($finance_i/$finance_count*100);
            }

            $govern_i = 0;
            $govern_count = count($info['govern']);
            foreach ($info['govern'] as $k => $v) {
                if($v==1){
                    $govern_i = $govern_i+1;
                }
                $info['govern']['v'] = ceil($govern_i/$govern_count*100);
            }

            $operate_i = 0;
            $operate_count = count($info['operate']);
            foreach ($info['operate'] as $k => $v) {
                if($v==1){
                    $operate_i = $operate_i+1;
                }
                $info['operate']['v'] = ceil($operate_i/$operate_count*100);
            }

            $obj_i = 0;
            $obj_count = count($info['obj']);
            foreach ($info['obj'] as $k => $v) {
                if($v==1){
                    $obj_i = $obj_i+1;
                }
                $info['obj']['v'] = ceil($obj_i/$obj_count*100);
            }

            $infos_i = 0;
            $infos_count = count($infos);
            foreach ($infos as $k => $v) {
                if($v==1){
                    $infos_i = $infos_i+1;
                }
                $infos['v'] = ceil($infos_i/$infos_count*100);
            }
             //解读
            $map = array();
            $map['id'] = I('post.id');
            $r = D('CircleAnnounce')->get_one($map);
            $user_id = $r['user_id'];
            $map['id'] = $user_id;
            $r['user'] =D('User')->get_one($map);
            $long = time()-$r['add_time'];
          // echo $long;
            if($long<60){
                $r['add_date'] = $long."秒前";
            }else if($long<3600){
                $r['add_date'] = ceil($long/60)."分钟前";
            }else if($long>3600 && $long<86400){
                $r['add_date'] = ceil($long/3600)."小时前";
            }else if($long>86400 && $long<259200){
                $r['add_date'] = ceil($long/86400)."天前";
            }else if($long>259200){
                $r['add_date'] = date('Y-m-d H:i:s',$add_time);
            }else if($long=0){
                $r['add_date'] = "刚刚";
            }
            //判断点赞
            $userid = I('post.userid');
            if($userid){
                $where['id_user'] = $userid;
                $where['type'] = 9;
                $where['id_target'] = I('post.id');
                $praise = D('Praise')->get_one($where);
                if($praise){
                    $r['is_praise'] = 1;
                }else{
                    $r['is_praise'] = 0;
                }
            }else{
                    $r['is_praise'] = 0;
            }

                //查询评论
            $map = array();
            $map['id_target'] = I('post.id');
            $map['type'] = 7;
            $map['p_id'] =0;
            $comment = D('Comment')->get_all($map);
            foreach ($comment as $k => $v) {
                 $long = time()-$v['add_time'];
                if($long<60){
                    $comment[$k]['add_date'] = $long."秒前";
                }else if($long<3600){
                    $comment[$k]['add_date'] = ceil($long/60)."分钟前";
                }else if($long>3600 && $long<86400){
                    $comment[$k]['add_date'] = ceil($long/3600)."小时前";
                }else if($long>86400 && $long<259200){
                    $comment[$k]['add_date'] = ceil($long/86400)."天前";
                }else if($long>259200){
                    $comment[$k]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
                }else if($long=0){
                    $comment[$k]['add_date'] = "刚刚";
                }

                if($userid){
                    $where['id_user'] = $userid;
                    $where['type'] = 3;
                    $where['id_target'] = $v['id'];
                    $praise = D('Praise')->get_one($where);
                 if($praise){
                        $comment[$k]['is_praise'] = 1;
                    }else{
                        $comment[$k]['is_praise'] = 0;
                    }
                }else{
                        $comment[$k]['is_praise'] = 0;
                }

                $map = array();
                $map['id'] = $v['user_id'];
                $comment[$k]['user'] = D('User')->get_one($map);
                $map = array();
                $map['p_id'] =$v['id'];
                $kid = D('Comment')->get_all($map);
                    foreach ($kid as $ke => $va) {
                        $map = array();
                        $map['id'] = $va['user_id'];
                        $kid[$ke]['user'] = D('User')->get_one($map);
                        //echo 
                        $long = time()-$va['add_time'];
                        if($long<60){
                             $kid[$ke]['add_date'] = $long."秒前";
                        }else if($long<3600){
                             $kid[$ke]['add_date'] = ceil($long/60)."分钟前";
                        }else if($long>3600 && $long<86400){
                             $kid[$ke]['add_date'] = ceil($long/3600)."小时前";
                        }else if($long>86400 && $long<259200){
                             $kid[$ke]['add_date'] = ceil($long/86400)."天前";
                        }else if($long>259200){
                             $kid[$ke]['add_date'] = date('Y-m-d H:i:s',$info['add_time']);
                        }else if($long=0){
                             $kid[$ke]['add_date'] = "刚刚";
                        }
                    }
                    $comment[$k]['kid'] = $kid;
            }
            //查询用户综合评价
            $platform_id =I('post.platform_id');
            $map = array();
            $map['user_id'] = $r['user_id'];
            $map['platform_id'] = $platform_id;
            $grade = D('PlatformGrade')->get_one($map);
            //print_r($r);die;

            if($infos or $r or $info or $grade or $comment or $platform_report){
                $arr = array('errorCode'=>1,'msg'=>"获取成功！",'data'=>array('res'=>$r,'info'=>$info,'infos'=>$infos['v'],'colligate'=>$grade['colligate'],'grade'=>$grade,'comment'=>$comment,'platform_report'=>$platform_report));
            }else{
                $arr = array('errorCode'=>0,'msg'=>"暂无数据！");
            }
                $this->ajaxReturn($arr);


    }


    //圈子舆情解读
    public function circle_opinion() {
        if(IS_POST) {
            $edit = I('post.edit');
            $user_id = I('post.userid');
            if($edit){
                $info_id = I('post.info_id');
                $map['id'] = $info_id;
                $o_info = D('CircleOpinion')->get_one($map);
                if($o_info['user_id']==$user_id){
                    $map = array();
                    $maps['id'] = $info_id;
                    $datas['content'] = I('post.content');
                    $r = D('CircleOpinion')->edit($maps,$datas);
                        if($r){
                            $data = array('errorCode'=>1,'msg'=>"编辑成功！",'r'=>$r);
                        }else{
                            $data = array('errorCode'=>0,'msg'=>"编辑失败！");
                        }
                     $this->ajaxReturn($data);
                }else{
                    $data = array('errorCode'=>2,'msg'=>"非法操作");
                    $this->ajaxReturn($data);
                }
            }
            $user_role = I('post.role');
            $card_status = I('post.card_status');
            if($card_status==0){
                $data = array('errorCode'=>2,'msg'=>"您未实名认证提交失败！");
                $this->ajaxReturn($data);
            }
            $postdata = I('post.');
            if($user_role==2){
                $postdata['user_role']=2;
            }else{
                $postdata['user_role']=1;
            }
            $postdata['platform_id'] = I('post.platform_id');
            $postdata['user_id'] = $user_id;
            $postdata['add_time'] = time();
            $r = D('CircleOpinion')->add($postdata);
            if($r){
                $data = array('errorCode'=>1,'msg'=>"提交成功！",'r'=>$r);
            }else{
                $data = array('errorCode'=>0,'msg'=>"提交失败！");
            }
            $this->ajaxReturn($data);
        } else {
            $edit = I('get.edit');
            if($edit){
                $info_id = I('get.info_id');
                $platform_id = I('get.id');
                $map['id'] = $info_id;
                $circle_info = D('CircleOpinion')->get_one($map);
                if($circle_info) {
                    $data = array('errorCode'=>1,'msg'=>"获取成功！",'edit'=>1,'circle_info'=>$circle_info);
                    $this->ajaxReturn($data);
                }
            }
            $map = array();
            $user_id = I('get.userid');
            $platform_id =I('get.id');
            $map['platform_id'] = $platform_id;
            $map['user_id'] = $user_id;
            $r = D('PlatformGrade')->get_one($map);
        //    print_r($r);die;
            $this->assign('colligate',$r['colligate']);
            $this->assign('is_invest',$r['is_invest']);
            if($r){
                $data = array('errorCode'=>1,'msg'=>"获取成功！",'colligate'=>$r['colligate'],'is_invest'=>$r['is_invest']);
            }
            $this->ajaxReturn($data);
        }
    }


    /**
     * [correction 补充，纠错]
     * @return [type] [description]
     */
    public function correction(){
        $postdata = I('post.');
        $postdata['user_id'] = I('post.userid');
        $postdata['add_time'] = time();
        $r = D('PlatformCorrection')->data($postdata)->add();
        if($r){
            $data = array('errorCode'=>1,'msg'=>"提交成功！",'r'=>$r);
        }else{
            $data = array('errorCode'=>0,'msg'=>"提交失败！");
        }
        $this->ajaxReturn($data);
    }



    //徒弟列表
    public function pupil_list(){
        $userid = I('post.userid');
        $map['referral'] = $userid; 
        $list = D('User')->get_all($map);
        if($list) {
            $data = array('errorCode'=>1,'msg'=>"获取成功",'data'=>$list);
        } else {
            $data = array('errorCode'=>0,'msg'=>"暂无数据");
        }
        $this->ajaxReturn($data);
    }


    //设置红包
    public function set_pack(){
        $platform_id = I('get.platform_id');
        $userid = I('get.userid');
        if(IS_POST){
            $scheme_id = I('post.scheme_id');
            $user_award = I('post.user_award');
            $push_award = I('post.push_award');
            $set_res =  R('Packet/set_redpacket',array('platform_id'=>$platform_id,'scheme_id'=>$scheme_id,'userid'=>$userid,'user_award'=>$user_award,'push_award'=>$push_award));

            if($set_res) {
                $data = array('errorCode'=>1,'msg'=>"设置红包成功",'data'=>$set_res);
            } else {
                $data = array('errorCode'=>0,'msg'=>"暂无数据");
            }
            $this->ajaxReturn($data);
        }else{
            $packet_list = R('Packet/get_redpacket',array('userid'=>$userid,'platform_id'=>$platform_id));
            if($packet_list) {
                $data = array('errorCode'=>1,'msg'=>"获取成功",'data'=>$packet_list);
            } else {
                $data = array('errorCode'=>0,'msg'=>"暂无数据");
            }
            $this->ajaxReturn($data);
        }
    }


}